package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.UserFreeze;
import com.itheima.mapper.UserFreezeMapper;
import com.itheima.service.db.FreezeService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class FreezeServiceImpl implements FreezeService {
    @Autowired
    private UserFreezeMapper userFreezeMapper;
    @Override
    public void save(UserFreeze userFreeze) {
        userFreezeMapper.insert(userFreeze);
    }

    @Override
    public void remove(Long userId) {
        QueryWrapper<UserFreeze> qw = new QueryWrapper<>();
        qw.eq("user_id",userId);
        userFreezeMapper.delete(qw);
    }

    @Override
    public UserFreeze findFreeze(Long userId) {
        QueryWrapper<UserFreeze> qw = new QueryWrapper<>();
        qw.eq("user_id",userId).orderByDesc("created");
        List<UserFreeze> userFreezeList = userFreezeMapper.selectList(qw);
        return userFreezeList.get(0);
    }

    @Override
    public void update(UserFreeze userFreeze,Long id) {
        QueryWrapper<UserFreeze> qw = new QueryWrapper<>();
        qw.eq("id",id);
        userFreezeMapper.update(userFreeze,qw);
    }
}
